import { Cache_Key } from '@/config'
const useCachePage = () => {
  const setCachePage = (params: any) => {
    const pathname = window.location.pathname
    const cachePage = window.sessionStorage.getItem(Cache_Key)
      ? JSON.parse(window.sessionStorage.getItem(Cache_Key)!)
      : {}
    cachePage[pathname] = params
    window.sessionStorage.setItem(Cache_Key, JSON.stringify(cachePage))
  }
  const getCachePage = () => {
    const pathname = window.location.pathname
    const cachePage = window.sessionStorage.getItem(Cache_Key)
      ? JSON.parse(window.sessionStorage.getItem(Cache_Key)!)
      : {}
    return cachePage[pathname] || null
  }
  return { setCachePage, getCachePage }
}
export default useCachePage
